﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Infrastructure.Data.PermisosModule.Context;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Domain.PermisosModule.Contracts.Concesiones;
using Cesave.Infrastructure.Data.PermisosModule.Repositories;

namespace Cesave.Infrastructure.Data.PermisosModule.Tests.RepositoriesTests
{
	[TestClass]
	public class ConcesionRepositoryTests
		: GenericRepositoryTestsBase<Concesion>
	{

		public override System.Linq.Expressions.Expression<Func<Concesion, bool>> FilterExpression
		{
			get
			{
				return c => c.ConcesionId == 1;
			}
		}

		public override System.Linq.Expressions.Expression<Func<Concesion, int>> OrderByExpression
		{
			get
			{
				return c => c.ConcesionId;
			}
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void FindConcesionByGuid_Null_Specification_Throws_ArgumentNullException()
		{
			// Arrange
			IPermisosModuleContext context = GetContext();
			ITraceManager traceManager = GetTraceManager();
			IConcesionRepository repository = new ConcesionRepository(context, traceManager);

			// Act
			var actual = repository.FindConcesionByGuidSpecification(null);
		}

		[TestMethod]
		[ExpectedException(typeof(InvalidOperationException))]
		public void FindConcesionesByGuid_Empty_Guid_Throws_InvalidOperationException()
		{
			// Arrange
			IPermisosModuleContext context = GetContext();
			ITraceManager traceManager = GetTraceManager();
			IConcesionRepository repository = new ConcesionRepository(context, traceManager);

			ConcesionByGuidSpecification specification = new ConcesionByGuidSpecification(Guid.Empty);

			// Act
			var actual = repository.FindConcesionByGuidSpecification(specification);
		}

		[TestMethod]
		public void FindConcesionesByGuid_Invoke()
		{
			// Arrange
			IPermisosModuleContext context = GetContext();
			ITraceManager traceManager = GetTraceManager();
			IConcesionRepository repository = new ConcesionRepository(context, traceManager);

			Guid guid = new Guid("1BA4123A-2F47-4303-B4C2-8DD72FA15AA8");

			ConcesionByGuidSpecification specification = new ConcesionByGuidSpecification(guid);

			// Act
			var actual = repository.FindConcesionByGuidSpecification(specification);

			// Assert
			Assert.IsNotNull(actual);
			Assert.AreEqual(1, actual.ConcesionId);
		}

	}
}
